using Microsoft.AspNetCore.Mvc;

namespace JaegerDemo.BFF.Host.Controllers;

[ApiController]
[Route("[controller]")]
public class BFFValueController : ControllerBase
{
    private readonly IHttpClientFactory _httpClientFactory;

    public BFFValueController(IHttpClientFactory httpClientFactory)
    {
        _httpClientFactory = httpClientFactory;
    }

    [HttpGet]
    public async Task<string> GetAsync()
    {
        using var httpClient = _httpClientFactory.CreateClient();
        httpClient.BaseAddress = new Uri("https://localhost:7001");

        var aServiceResult = await httpClient.GetStringAsync("/AValue");
        return aServiceResult;
    }

    [HttpPost]
    public async Task<string> CreateAsync()
    {
        using var httpClient = _httpClientFactory.CreateClient();
        httpClient.BaseAddress = new Uri("https://localhost:7001");

        var httpContent = new StringContent("");
        var aServiceResult = await httpClient.PostAsync($"/AValue?value={DateTime.Now}", httpContent);
        var httpResponseContent = await aServiceResult.Content.ReadAsStringAsync();
        return httpResponseContent;
    }
}